<template>
    <div class="provide-inject">
        <h1>provide / inject</h1>
        <div ref="BarChartRef" class="echart"></div>
    </div>
</template>
<script setup>
import { ref, onMounted, inject } from 'vue'
const BarChartRef = ref()
onMounted(() => {
    // 注入echarts实例
    const echarts = inject("echarts");
    // 基于准备好的dom，初始化echarts实例
    const BarChart = echarts.init(BarChartRef.value);
    // 绘制图表
    BarChart.setOption({
        title: {
            text: '柱状图'
        },
        tooltip: {},
        xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
            {
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }
        ]
    });
})
</script>
<style lang="scss" scoped>
.provide-inject {
    margin: auto;
    max-width: 60vw;

    .echart {
        width: 100%;
        height: 500px;
    }
}
</style>